-- 创建咸鱼基础技能
local wdtx_xianyu = fk.CreateSkill {
  name = "wdtx_xianyu",
  tags = { Skill.Compulsory }
}

Fk:loadTranslationTable {
  ["wdtx_xianyu"] = "咸鱼",
  ["#wdtx_xianyu_maxhands"] = "咸鱼",
  [":wdtx_xianyu"] = "锁定技，本回合结束，若期间没有造成伤害则每回合受到伤害-1直到下回合结束，若期间没有使用牌或使用牌指向目标只为自己则获得‘凌心’标记+1（增加手牌上限，最多+5），否则移除以此法获得的‘凌心’。"
}

wdtx_xianyu:addEffect(fk.TurnEnd, {
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self.name) then return end
    return target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local havedamage, haveusecard
    room.logic:getEventsOfScope(GameEvent.Damage, 3, function(e)
      for _,info in ipairs(e.data) do
        if info.from and info.from == player and info.damage > 0 then
          havedamage = true
        end
      end
    end, Player.HistoryTurn)
    room.logic:getEventsOfScope(GameEvent.UseCard, 99, function(e)
      for _,info in ipairs(e.data) do
        if info.from and info.from == player and info.tos and table.find(info.tos,function(t) return player.id ~= t.id end) then
          haveusecard = true
        end
      end
    end, Player.HistoryTurn)
    if not havedamage then
      room:setPlayerMark(player,"xy_reddamaged",1)
    else
      room:setPlayerMark(player,"xy_reddamaged",0)
    end

    if not haveusecard then
      local lingxinbyskill = player:getMark("xy_lingxin")
      if lingxinbyskill < 5 then
        room:addPlayerMark(player,"xy_lingxin",1)
        room:addPlayerMark(player,"@df_lingxin",1)
      end
    else
      local lingxinbyskill = player:getMark("xy_lingxin")
      if lingxinbyskill > 0 then
        room:removePlayerMark(player,"xy_lingxin",lingxinbyskill)
        room:removePlayerMark(player,"@df_lingxin",lingxinbyskill)
      end
    end
  end
})

wdtx_xianyu:addEffect(fk.DamageInflicted, {
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self.name) then return end
    return data.to == player and player:getMark("xy_reddamaged") > 0 and
    player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage - 1
  end
})

wdtx_xianyu:addEffect("maxcards", {
  correct_func = function(self, player)
    if player:hasSkill(wdtx_xianyu.name) and player:getMark("@df_lingxin") > 0 then
      return player:getMark("@df_lingxin")
    end
    return 0
  end
})


return wdtx_xianyu